<?php
// +----------------------------------------------------------------------
// | 麦沃德科技赋能开发者，助力中小企业发展
// +----------------------------------------------------------------------
// | Copyright (c) 2017～2024  www.wdadmin.cn    All rights reserved.
// +----------------------------------------------------------------------
// | Wdadmin系统产品软件并不是自由软件，不加密，并不代表开源，未经许可不可自由转售和商用
// +----------------------------------------------------------------------
// | Author: MY WORLD Team <bd@maiwd.cn>   www.wdadmin.cn
// +----------------------------------------------------------------------
/**
 * Class Order
 * Desc  代驾订单Model
 * Create on 2024/10/28 11:47
 * Create by wangyafang
 */

namespace app\api\model\wddj\trailer;


use app\api\model\wddj\user\Passenger;
use app\api\model\wddj\user\UserRealNameAuthentication;
use think\Model;

class Order extends Model
{
// 表名
    protected $name = 'wddj_order_trailer';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    protected $deleteTime = false;

    public function getMobileAttr($value, $data)
    {
        $mobile = self::getMobile($data);
        return $mobile;
    }

    public static function getMobile($data)
    {
        if (!empty($data['passenger_id'])) {
            $mobile = (new Passenger())->where('id',$data['passenger_id'])->value('mobile');
        } else {
            $mobile = (new UserWechat())->where('id',$data['wechat_id'])->value('mobile');
        }

        return $mobile;
    }

    /**
     * Desc 订单详情获取乘车人信息
     * Create on 2024/11/5 9:14
     * Create by wangyafang
     */
    public static function getPassenger($orderObj)
    {
        if (!empty($orderObj['passenger_id'])) {
            $passengerObj = (new Passenger())->get($orderObj['passenger_id']);
            $data = array(
                'name'=>$passengerObj['name'],
                'mobile'=>$passengerObj['mobile'],
            );
        } else {
            $userRealNameAuthenticationName = (new UserRealNameAuthentication())->where('wechat_id',$orderObj['wechat_id'])->value('name');
            $userWechatObj = (new \app\api\model\wddj\UserWechat())->get($orderObj['wechat_id']);
            $data = array(
                'name'=>!empty($userRealNameAuthenticationName) ? $userRealNameAuthenticationName : $userWechatObj['nickname'],
                'mobile'=>substr_replace($userWechatObj['mobile'], '*****', 3, -3),
            );
        }

        return $data;

    }
}



 